package org.example.io;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public class TestFileOutputStream {

    public static void main(String[] args) throws Exception {
        // 使用File对象创建流对象
        File file = new File("D:\\tmp\\111.txt");
        FileOutputStream outputStream = new FileOutputStream(file);
        // 使用文件名称创建流对象
        FileOutputStream stream = new FileOutputStream("D:\\tmp\\111.txt");

        //写出数据
        stream.write("111".getBytes());
        //刷新此输出流并强制任何缓冲的输出字节被写出
        stream.flush();
        //关闭输出流
        stream.close();

        //开启文件续写
        FileOutputStream fileOutputStream = new FileOutputStream("D:\\tmp\\111.txt", true);
        //写出数据
        fileOutputStream.write(97);
        //换行符
        fileOutputStream.write("\r\n111".getBytes());
        //刷新此输出流并强制任何缓冲的输出字节被写出
        fileOutputStream.flush();
        //关闭输出流
        fileOutputStream.close();
    }

}
